package zhoufu.sz.sanxiao_check.ui.adapter;

import android.content.Context;
import android.view.animation.BounceInterpolator;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import com.github.aakira.expandablelayout.ExpandableRelativeLayout;
import java.util.List;
import org.byteam.superadapter.recycler.BaseViewHolder;
import org.byteam.superadapter.recycler.SuperAdapter;
import zhoufu.sz.sanxiao_check.R;
import zhoufu.sz.sanxiao_check.models.DangerModel;
import zhoufu.sz.sanxiao_check.utils.UIUtils;


/**
 * User:RCP
 * email:ruancaipu@gmail.com
 * Date:2016/7/30
 */
public class CheckItemAdapter extends SuperAdapter<DangerModel>
{
    public CheckItemAdapter(Context context, List items, int layoutResId)
    {
        super(context, items, layoutResId);
    }

    @Override public void onBind(int viewType, BaseViewHolder holder, int position,
            DangerModel item)
    {
        holder.setText(R.id.mTvLine, String.valueOf(position + 1));
        holder.setText(R.id.mTvCheckItemName, item.getContent());
        holder.setText(R.id.mTvCheckItemSteps, item.getMeasure());
        CheckBox box = holder.getView(R.id.mBox);
        box.setChecked(item.getIs_Ok() > 0 ? true : false);
        final ExpandableRelativeLayout layout = holder.getView(R.id.expandableLayout);
        if ( item.getIs_Ok() > 0 )
        {
            holder.setBackgroundRes(R.id.mTvLine, R.drawable.shape_oval_backpage_red);
            holder.setTextColor(R.id.mTvCheckItemName, UIUtils.getColor(R.color.viewfinder_laser));
        } else
        {
            holder.setBackgroundRes(R.id.mTvLine, R.drawable.shape_oval_backpage_gray);
            holder.setTextColor(R.id.mTvCheckItemName, UIUtils.getColor(R.color.black));
        }
        box.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
        {
            @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
            {
                if ( isChecked )
                {
                    layout.collapse(400, new BounceInterpolator());
                } else
                {
                    layout.expand(400, new BounceInterpolator());
                }
            }
        });
    }
}
